package com.zle.services.login;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zle.common.util.DateUtil;
import com.zle.dao.UserMapper;
import com.zle.entity.User;
import com.zle.entity.UserExample;
import com.zle.entity.UserExample.Criteria;

@Service
public class LoginService implements ILoginService{
	
	@Autowired
	UserMapper userMapper;
	public User checkUser(String name,String pwd){
		UserExample example = new UserExample();
		Criteria criteria = example.createCriteria();
		criteria.andNameEqualTo(name);
		criteria.andPwdEqualTo(pwd);
		
		List<User> rows = userMapper.selectByExample(example);
		if(rows.isEmpty()){
			return null;
		}else{
			return rows.get(0);
		}
	}
	public boolean unameAddExist(String uname){
		UserExample example = new UserExample();
		Criteria criteria = example.createCriteria();
		criteria.andNameEqualTo(uname);
		List<User> rows = userMapper.selectByExample(example);
		return rows.isEmpty();
	}
	public void addUser(String uname,String upwd,String email,String phone,String ip){
		
		User record = new User();
		record.setName(uname);
		record.setPwd(upwd);
		record.setEmail(email);
		record.setIp(ip);
		record.setCreateTime(DateUtil.getCurrentTime());
		userMapper.insert(record);
	}
}
